{extend name="public/base"/}

{block name="title"}权限节点管理{/block}
{block name="main"}
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-toolbar clearfix">
                <div class="toolbar-btn-action">
                    <a class="btn btn-primary m-r-5" href="/admin/permission/add"><i class="mdi mdi-plus"></i> 新增</a>
                </div>
            </div>
            <div class="card-body">

                <div class="table-responsive">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th>
                                <label class="lyear-checkbox checkbox-primary">
                                    <input type="checkbox" id="check-all"><span></span>
                                </label>
                            </th>
                            <th>ID</th>
                            <th>节点名称</th>
                            <th>路径</th>
                            <th>所属目录</th>
                            <th>排序码</th>
                            <th>是否为菜单</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="list" id="vo"}
                        <tr>
                            <td>
                                <label class="lyear-checkbox checkbox-primary">
                                    <input type="checkbox" name="ids[]" value="1"><span></span>
                                </label>
                            </td>
                            <td>{$vo.id}</td>
                            <td>{$vo.name}</td>
                            <td>{$vo.path}</td>
                            <td>{$vo.category}</td>
                            <td>{$vo.sort_num}</td>
                            {eq name = "$vo.is_menu" value="1"}
                            <td><span class="text-success">是</span></td>
                            {else}
                            <td><span class="text-fade">否</span></td>
                            {/eq}
                            <td>
                                <div class="btn-group">
                                    <a class="btn btn-xs btn-default" id="edit" title="编辑" onclick="edit({$vo.id});"
                                       data-toggle="tooltip"><i class="fa fa-pencil" aria-hidden="true"></i>编辑</a>
                                    <a class="btn btn-xs btn-default" id="del" title="删除" onclick="del({$vo.id});"
                                       data-toggle="tooltip"><i class="fa fa-close" aria-hidden="true"></i>删除</a>
                                </div>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                {$list|raw}
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
    //编辑
    function edit(id) {
        window.location.href = `/admin/permission/edit?id=${id}`;
    }

    //删除
    function del(id) {
        swal('确定要删除该节点吗?', {
            icon: 'warning',
            dangerMode: true,
            buttons: {
                cancel: {
                    text: "取消",
                    value: false,
                    visible: true,
                    className: "",
                    closeModal: true,
                },
                confirm: {
                    text: "确认",
                    value: true,
                    visible: true,
                    className: "",
                    closeModal: true
                }
            }
        }).then((rst) => {
            if (rst) {
                $.post('/admin/permission/del',
                    {id: id},
                    function (res) {
                        if (res.code === 1) {
                            swal(res.msg, '', 'success')
                                .then(() => {
                                    location.reload();
                                });
                        } else {
                            swal(res.msg, '', 'error');
                        }
                    });
            }
        });
    }
</script>
{/block}